<template>
	<view class="user">
		<view class="user_content">
			<view class="user_detail">
				<view class="uer_info">
					<view class="header_info">
						<view class="header_info_title" v-if="userInfo === false" @click="ClickLogin()">
							<view class="header_photo">
								<image src="../../static/3x/tjxhT.png"></image>
							</view>
							<view class="header_Name">
								请登录
							</view>
						</view>
						<view class="header_info_title" v-else>
							<view class="header_photo" v-if="userList.avatar" @click="SzClick()">
								<image :src="util.imageApi+userList.avatar"></image>
							</view>
							<view class="header_photo" v-else @click="SzClick()">
								<image src="../../static/3x/tjxhT.png"></image>
							</view>
							<view class="header_Name">
								<view class="">
									{{userList.nickName}}
								</view>
								<view class="">
									ID:{{userList.memberId}}
								</view>
								<view class="">
									{{userList.memberLevelName?userList.memberLevelName:'认养户'}}
								</view>
							</view>
							<view class="header_prije">
								<view class="">
									今日健康值：{{priceScore | changePriceScore}}
								</view>
								<view class="header_chicken" @click="handleDetailed(7)">
									{{userList.grade}}
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="integral">
				<view class="consumption" @click="handleDetailed(1)">
					<view class="number" v-if="price.adoptVoucher!=null">
						{{price.adoptVoucher}}
					</view>
					<view class="name">
						认养券
					</view>
				</view>
				<view class="give" @click="handleDetailed(3)">
					<view class="number" v-if="price.pointsStatic!=null">
						{{price.pointsStatic}}
					</view>
					<view class="name">
						健康分
					</view>
				</view>
				<view class="shopping" @click="handleDetailed(2)">
					<view class="number" v-if="price.pointsDynamic!=null">
						{{price.pointsDynamic}}
					</view>
					<view class="name">
						鸡蛋
					</view>

				</view>
				<view class="shopping" @click="handleDetailed(4)">
					<view class="number" v-if="price.shoppingVoucher!=null">
						{{price.shoppingVoucher}}
					</view>
					<view class="name">
						消费券
					</view>
				</view>
				<view class="shopping" @click="handleDetailed(6)">
					<view class="number" v-if="price.cash!=null">
						{{price.cash}}
					</view>
					<view class="name">
						余额
					</view>
				</view>
			</view>
		</view>
		<view class="notice" v-if="text">
			<u-notice-bar :text="text" direction="row" mode="link" bgColor="white" url="/subpackages/gonggao/gonggao">
			</u-notice-bar>
		</view>
		<view class="notice1" v-else>
		</view>
		<view class="order_icon">
			<view class="header_icon_title">
				<view class="title_name">
					商城订单
				</view>
				<!-- <view class="title_icon">
					全部订单
					<uni-icons type="forward" color="#565656"></uni-icons>
				</view> -->
			</view>
			<view class="header_icon_info">
				<view class="icon_info" v-for="(item,index) in orderList" :key="index" @click="ClickSC(0,item.index)">
					<view class="icon">
						<image :src="item.imageUrl"></image>
						<span class="red" v-if="item.sum">{{item.sum}}</span>
					</view>
					<view class="icon_name">
						{{item.name}}
					</view>
				</view>
			</view>
		</view>
		<view class="order_icon view">
			<view class="header_icon_info">
				<view class="icon_info infoin" v-for="(item,index) in converList" :key="index" @click="ClickCy(item)">
					<view class="icon">
						<image :src="item.imageUrl"></image>
					</view>
					<view class="icon_name">
						{{item.name}}
					</view>
				</view>
			</view>
		</view>

		<u-popup :show="show" mode="center" @close="handleClose" :round="10">
			<view class="LoginUser">
				<view class="title">
					请登录
				</view>
				<button class="button" @click="ClickGo()">
					去登录
				</button>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import util from "@/util/index.js"
	export default {
		data() {
			return {
				selfBuying: 0,
				text: "",
				statusObj: {},
				visible: false,
				util: util,
				priceScore: 0,
				price: {},
				show: false,
				userList: {},
				userInfo: false,
				ID: '',
				orderList: [{
					name: '待付款',
					imageUrl: 'https://s1.ax1x.com/2022/05/20/OLourt.png',
					index: 0,
					type: 0
				}, {
					name: '待发货',
					imageUrl: 'https://s1.ax1x.com/2022/05/20/OLoexA.png',
					index: 1,
					type: 1
				}, {
					name: '待收货',
					imageUrl: 'https://s1.ax1x.com/2022/05/20/OLola8.png',
					index: 2,
					type: 2
				}, {
					name: '待评价',
					imageUrl: 'https://s1.ax1x.com/2022/05/20/OLo1IS.png',
					index: 3,
					type: 3
				}],
				teamList: [{
					name: '我的团队',
					imageUrl: 'https://s1.ax1x.com/2022/03/15/bvIOMQ.png',
					path: '/pages/team/team'
				}, {
					name: '签到明细',
					imageUrl: 'https://s1.ax1x.com/2022/03/15/bvIXrj.png',
					path: '/pages/SignDetail/SignDetail'
				}, {
					name: '推荐码',
					imageUrl: 'https://s1.ax1x.com/2022/03/15/bvIjqs.png',
					path: '/pages/yard/yard'
				}],
				converList: [{
						name: '我的认养',
						imageUrl: '../../static/3x/star-states.png',
						index: 0,
						path: '/pages/myxiaoji/myxiaoji'
					}, {
						name: '领取鸡蛋',
						imageUrl: 'https://s1.ax1x.com/2022/05/20/OLoaq0.png',
						index: 1,
						path: '/pages/getEggs/getEggs'
					}, {
						name: '账户转换',
						imageUrl: 'https://s1.ax1x.com/2022/05/20/OLo0aT.png',
						index: 2,
						path: '/pages/accountConversion/accountConversion'
					}, {
						name: '会员转账',
						imageUrl: 'https://s1.ax1x.com/2022/05/20/OLoyRJ.png',
						index: 30,
						path: '/pages/vipTransfer/vipTransfer'
					}, {
						name: '推广码',
						imageUrl: 'https://s1.ax1x.com/2022/05/20/OLoRqx.png',
						index: 4,
						path: '/pages/yard/yard'
					},
					{
						name: '销售社区',
						imageUrl: 'https://s1.ax1x.com/2022/05/20/OLRlpq.png',
						index: 5,
						path: '/pages/sales/sales'
					},
					{
						name: '财务中心',
						imageUrl: 'https://s1.ax1x.com/2022/05/20/OLo6z9.png',
						index: 6,
						path: '/pages/finance/finance'
					}, {
						name: '切换账号',
						imageUrl: '../../static/3x/2.png',
						index: 7,
						path: ''
					}, {
						name: '设置',
						imageUrl: '../../static/3x/repeat.png',
						index: 8,
						path: '/pages/setUp/setUp'
					},

				],
				giftList: [{
					name: '待发货',
					imageUrl: 'https://s1.ax1x.com/2022/03/15/bvoZZR.png',
					index: 1
				}, {
					name: '待收货',
					imageUrl: 'https://s1.ax1x.com/2022/03/15/bvoui6.png',
					index: 2
				}, {
					name: '售后',
					imageUrl: 'https://s1.ax1x.com/2022/03/15/bvoEL9.png',
					index: 4
				}]
			}
		},
		onPullDownRefresh() {
			setTimeout(() => {
				uni.stopPullDownRefresh()
			}, 1000)
		},
		methods: {
			//公告栏
			SearchAnnMsessage() {
				this.$http({
					url: '/crmMessage/selAnnMessage'
				}).then(res => {
					const that = this
					res.data.data.forEach(function(item, index) {
						if (item.id == 3) {
							that.text = res.data.data[index].body
						}
					})
				})
			},
			handleClose() {

			},
			ClickGo() {
				//#ifdef APP-PLUS || H5
				uni.navigateTo({
					url: '/pages/Applogin/Applogin'
				})
				//#endif
				//#ifdef MP-WEIXIN
				if (this.code === 423) {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				} else if (this.code === 401) {
					uni.getUserProfile({
						desc: '登陆',
						success: (res) => {
							this.$http({
								url: '/MemberLogin/MemberAppletLogin',
								method: 'POST',
								data: {
									nickName: res.userInfo.nickName,
									openId: this.openId,
									avatarUrl: res.userInfo.avatarUrl,
									gender: res.userInfo.gender,
									sharer: ''
								},
							}).then(res => {
								if (res.data.code === 200) {
									uni.setStorageSync('secretKey', res.data.data);
									uni.showToast({
										title: '登陆成功',
										icon: 'success'
									})
									this.show = true
									this.SearchShop()
								} else if (res.data.code === 422) {
									uni.showToast({
										title: res.data.message,
										icon: 'error'
									})
								}
							})
						}
					})
				}
				//#endif
			},
			SzClick() {
				uni.navigateTo({
					url: '/pages/person-detail/person-detail'
				})
			},
			ClickSC(item, index) {
				uni.navigateTo({
					url: `/pages/siteShow/siteShow?item=` + item + `&index=` + index
				})
			},
			ClickCy(item) {
				if (item.name === "兑换鸡蛋") {
					uni.switchTab({
						url: item.path
					})
				} else {
					uni.navigateTo({
						url: item.path
					})
				}
				if (item.index === 7) {
					uni.removeStorageSync("secretKey")
					uni.reLaunch({
						url: "/pages/user/user"
					})
					this.price = {}
					this.userInfo = false
				} else if (item.index === 3 && uni.getStorageSync("secretKey") && this.userInfo) {
					uni.showLoading({
						title: '正在获取验证码'
					})
					this.$http({
						url: "/MemberLogin/sendSms",
						data: {
							templateId: 'SMS_241100166',
							phoneNumberSet: this.userList.userName
						}
					}).then(res => {
						if (res.data.code === 200 && res.data.data) {
							uni.$u.toast('验证码已发送');
							uni.showModal({ //提醒用户更新
								title: "请输入验证码注销账号？",
								content: "",
								editable: true,
								placeholderText: "请输入验证码",
								success: (resp) => {
									this.$http({
										url: "/member/cancellation",
										method: "GET",
										data: {
											verifyCode: resp.content
										}
									}).then(res => {
										if (res.data.code === 200) {
											uni.showToast({
												title: '注销成功',
												icon: 'success'
											})
											uni.removeStorageSync("secretKey")
											uni.reLaunch({
												url: "/pages/user/user"
											})
											this.price = {}
											this.userInfo = false
										} else {
											uni.showToast({
												title: res.data.message,
												icon: 'error'
											})
										}
									})
								}
							})
						} else {

						}
					})

				} else {
					uni.navigateTo({
						url: item.path
					})
				}

			},
			IntegralClick() {
				uni.navigateTo({
					url: '/pages/integral_detail2/integral_detail2?value=' + '3'
				})
			},
			GoldDustClick() {
				uni.navigateTo({
					url: '/pages/integral_detail/integral_detail?value=' + '6'
				})
			},
			FortVenClick() {
				uni.navigateTo({
					url: '/pages/FortVenosa/FortVenosa'
				})
			},
			HeaderClick(item) {
				uni.navigateTo({
					url: item.path
				})
			},
			ClickLogin() {
				uni.navigateTo({
					url: '/pages/Applogin/Applogin'
				})
			},
			SearchUser() {
				this.$http({
					url: "/member/getMyPage"
				}).then(res => {
					this.ID = res.data.data.memberId
					this.converList[0].path = '/pages/myxiaoji/myxiaoji?ID=' + this.ID
					this.selfBuying = res.data.data.selfBuying
					this.code = res.data.code
					if (res.data.code === 200) {
						this.userList = res.data.data
						this.userInfo = true
					} else if (res.data.code == 423) {
						this.show = true
					}
				})
			},
			handleDetailed(type) {
				uni.navigateTo({
					url: `/pages/detailed/detailed?type=` + type
				})
			},
			getInit() {
				// 查询各类余额
				this.$http({
					url: '/member/getMemberAccount',
				}).then(res => {
					if (res.data.code === 200) {
						this.price = res.data.data
					} else {
						this.price = {}
					}
				})

				// 查询健康分价格
				this.$http({
					url: '/member/selectHealthScoreNum',
					method: 'GET'
				}).then(res => {
					if (res.data.code === 200) {
						this.priceScore = res.data.data.variableValue
					} else {
						this.priceScore = ""
					}
				})
			}

		},
		onLoad() {
			this.SearchAnnMsessage()
		},
		onShow() {
			this.SearchUser()
			this.getInit()
			// 获取各种状态的数量
			this.$http({
				url: '/member/getMemberOrderStatusCount',
				method: "GET"
			}).then(res => {
				if (res.data.code === 200) {
					this.statusObj = res.data.data
					this.orderList.forEach(item => {
						let index = res.data.data.findIndex(k => k.status === item.type)
						if (index >= 0) {
							item.sum = res.data.data[index].count
						}
					})
				} else {}
			})
		},
		filters: {
			changePriceScore(value) {
				let sum = value
				if (value && value.split(".").length === 1) {
					sum += ".00"
				} else if (value && value.split(".").length > 1) {
					let str = value.split(".")[1]
					str.length === 1 ? sum += "0" : str.length > 2 ? sum.toFixed(2) : ""
				}
				return sum
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import './user.css'
</style>
